// components/GBTBasicInfo/GBTBasicInfo.js
const getdata = require("../../tool/GetDate.js")
const util = require("../../utils/util.js")
var app = getApp();
var currentPage = 0;
var listData = [];
var searchValue = "";

Page({

  /**
   * 页面的初始数据
   */
  data: {
    basic_list: [],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    currentPage = 0;
    listData = [];
    wx.setNavigationBarTitle({
      title: app.globalData.basic_title,
    });
    searchValue = "empty";
    this.getBasic(searchValue);
  },

  getBasic: function (name) {
    let that = this;
    currentPage++;
    getdata.getdata({
      url: app.globalData.basic_url + currentPage + "/",
      data: name,
      success: function (res) {
        console.log(res.root);
        if (res.root) {
          let list = res.root.data;
          for (let dataIndex = 0; dataIndex < list.length; dataIndex++) {
            listData.push(list[dataIndex]);
          }
          app.globalData.basic_list = listData;
          that.setData({
            basic_list: listData,
          });
        }
      },
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.getBasic(searchValue);
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  onSearch:function(e){
    searchValue = e.detail.value;
    currentPage = 0;
    listData = [];
    this.getBasic(searchValue);
  },

  onItemClick:function(e){
    console.log(e);
    app.globalData.basic_index = e.currentTarget.dataset.index;
    wx.navigateBack({
      delta: 1
    })
  },
})
